package com.example.idea.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 功能
 * 作者：妙笔生花
 * 日期：2024/9/7 23:21
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Bean
    public JwtInterceptor authenticationInterceptor() {
        return new JwtInterceptor();
    }
    // 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(authenticationInterceptor());
        registration.addPathPatterns("/**");//所有路径都被拦截  ,"/file/download/{fileName}"  , "/file/upload"
        registration.excludePathPatterns("/login/login","/orders/**",
                "/logs/**","/notice/**",
                "/news/**","/user/**",
                "/login/ZhuCe","/file/**",
                "/file/upload","/login/charts"
                ,"/login/charts1");
    }
}
